﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markup="clr-namespace:Elysium.Markup"
                    xmlns:params="clr-namespace:Elysium.Parameters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <Style TargetType="{x:Type CheckBox}">
        <Setter Property="Background" Value="{markup:ThemeResource BackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{markup:ThemeResource NormalBrush}"/>
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.DefaultThickness), Mode=OneWay}"/>
        <Setter Property="Foreground" Value="{markup:ThemeResource ForegroundBrush}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.ContentFontSize), Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="Medium"/>
        <Setter Property="FontStyle" Value="Normal"/>
        <Setter Property="FontWeight" Value="Normal"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldPadding), Mode=OneWay, Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter=Left}"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type CheckBox}">
                    <BulletDecorator Background="{markup:ThemeResource TransparentBrush}"
                                     TextBlock.Foreground="{TemplateBinding Foreground}"
                                     TextBlock.FontFamily="{TemplateBinding FontFamily}"
                                     TextBlock.FontSize="{TemplateBinding FontSize}"
                                     TextBlock.FontWeight="{TemplateBinding FontWeight}"
                                     FlowDirection="{TemplateBinding FlowDirection}"
                                     SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <BulletDecorator.Bullet>
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Width="{TemplateBinding params:Bullet.DecoratorSize}"
                                    Height="{TemplateBinding params:Bullet.DecoratorSize}">
                                <Grid>
                                    <Path x:Name="CheckBullet"
                                          Stroke="{markup:ThemeResource AccentBrush}"
                                          StrokeThickness="{TemplateBinding params:General.BoldThicknessValue}"
                                          Stretch="Fill"
                                          Visibility="Collapsed"
                                          Width="{TemplateBinding params:CheckBox.CheckSize}" Height="{TemplateBinding params:CheckBox.CheckSize}">
                                        <Path.Data>
                                            <GeometryGroup>
                                                <LineGeometry StartPoint="0,3" EndPoint="4,8"/>
                                                <LineGeometry StartPoint="4,8" EndPoint="8,0"/>
                                            </GeometryGroup>
                                        </Path.Data>
                                    </Path>
                                    <Path x:Name="IndeterminateBullet"
                                          Fill="{markup:ThemeResource AccentBrush}"
                                          StrokeThickness="0"
                                          Stretch="Fill"
                                          Visibility="Collapsed"
                                          Margin="2"
                                          Width="{TemplateBinding params:Bullet.Size}" Height="{TemplateBinding params:Bullet.Size}">
                                        <Path.Data>
                                            <GeometryGroup>
                                                <RectangleGeometry Rect="0,0,1,1"/>
                                            </GeometryGroup>
                                        </Path.Data>
                                    </Path>
                                </Grid>
                            </Border>
                        </BulletDecorator.Bullet>
                        <Border Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(params:General.BoldPaddingValue), Mode=OneWay, Converter={StaticResource DoubleToThicknessConverter}, ConverterParameter=Left}">
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              RecognizesAccessKey="True"/>
                        </Border>
                    </BulletDecorator>                    
                    <ControlTemplate.Triggers>						
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="CheckBullet" Property="Visibility" Value="Visible"/>
                        </Trigger>						
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsThreeState" Value="True"/>
                                <Condition Property="IsChecked" Value="{x:Null}"/>
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="IndeterminateBullet" Property="Visibility" Value="Visible"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>						
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="CheckBullet" Property="Path.Stroke" Value="{markup:ThemeResource DisabledBrush}"/>
                            <Setter TargetName="IndeterminateBullet" Property="Path.Fill" Value="{markup:ThemeResource DisabledBrush}"/>
                        </Trigger>						
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>        
        <Style.Triggers>			
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{markup:ThemeResource PaleBrush}"/>
                <Setter Property="BorderBrush" Value="{markup:ThemeResource NormalBrush}"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{markup:ThemeResource PaleBrush}"/>
                <Setter Property="BorderBrush" Value="{markup:ThemeResource HighlightBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{markup:ThemeResource BackgroundBrush}"/>
                <Setter Property="BorderBrush" Value="{markup:ThemeResource DisabledBrush}"/>
                <Setter Property="Foreground" Value="{markup:ThemeResource DisabledBrush}"/>
            </Trigger>
        </Style.Triggers>	        
    </Style>

</ResourceDictionary>